<?php
/***
 * 描述：广告推广
 * @category		Admin		
 * @package			Action			
 * @subpackage			
 * @author			wanght <whtaok@gmail.com>
 * @since			2013-4-6
 * @version			$Id: SpreadManageAction.class.php 6 2013-10-22 08:26:07Z whtaok@gmail.com $
 */
class SpreadAdAction extends AdminAction {
	private $savePath = '';
	private $typeList = array(
		'pc' => array(
				'index_top_lunxun' =>'首页轮询，590*240',
				'index_top_pic' =>'首页顶部，490*50',
				'index_mid_big' =>'首页中部，980*150',
				'index_mid_mid' =>'首页中部，490*100',
				'index_mid_sml' =>'首页中部，240*210',
				'index_btm_big' =>'首页中部，980*150',
			),
		'mobile' => array(
				'index_top_pic' =>'首页顶部，200*50',
				'index_mid_pic' =>'首页中部，200*50',
				'index_btm_pic' =>'首页底部，200*50',
		),
	
	);
	/**
	 *
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	protected  function _initialize() {
		parent::_initialize();
		$this->savePath =  C('REALPATH_SHOP').'/spreadad/';
		$this->assign('typeList',$this->typeList);
	}
	
	/**
	 * 显示推广管理页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function indexAct() {
		$mod = new CommonModel('ProductSpreadad');
		$modWhere = array(
			'type' => I('type'),
			'page_id' => I('page_id'),
			'title'=> I('title'),
		);
		$totalRows = $mod->setModWhere($modWhere)->count();
		list($list,$page) = $mod->setModWhere($modWhere)->order('type,page_id, ordlist')->listPage($totalRows);
		$this->assign('list',$list);
		$this->assign('page',$page);
		$this->display('index');
		
	}
	/**
	 * 显示添加页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function showAddAct() {
		$this->display('add');
	
	}
	
	/**
	 * 添加操作
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function doAddAct() {
		$mod = new CommonModel('ProductSpreadad');
		$mod->create();
		$mod->page_name = $this->typeList[I('type')][I('page_id')];
		$mod->add();
		$this->success('添加成功',U('index'));
	
	}
	
	/**
	 * 显示更新页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function showUpdAct($id) {
		$mod = new CommonModel('ProductSpreadad');
		$detail = $mod->find($id);
		$this->assign('detail',$detail);
		$this->display('upd');
	
	}
	
	/**
	 * 更新操作
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function doUpdAct($id) {
		$mod = new CommonModel('ProductSpreadad');
		$mod->create();
		$mod->save();
		$this->success('更新成功',U('index'));
	
	}
	
	
	/**
	 * 生成缓存热门/推荐商品列表页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */	
	public function doAddCacheAct(){
		F_CACHE($this->savePath.'pc',null);
		F_CACHE($this->savePath.'mobile',null);
		$mod = new CommonModel('ProductSpreadad');
		$modWhere['is_show'] = 1;
		$modWhere['type'] = 'pc';
		$pcListTmp = $mod->field('id,page_ref,pic,link,title')->setModWhere($modWhere)->order('page_id,ordlist')->select();
		$modWhere['type'] = 'mobile';
		$mobileListTmp = $mod->field('id,page_ref,pic,link,title')->setModWhere($modWhere)->order('page_id,ordlist')->select();
		$pcList = array();
		foreach ($pcListTmp as $key=>$value){
			$pcList[$value['page_ref']][] = $value;
		}
		foreach ($mobileListTmp as $key=>$value){
			$mobileList[$value['page_ref']][] = $value;
		}
		F_CACHE($this->savePath.'pc',$pcList);
		F_CACHE($this->savePath.'mobile',$mobileList);
		unset($pcList);
		unset($mobileList);
		unset($pcListTmp);
		unset($mobileListTmp);
		$this->success('缓存数据生成成功');
	}
	
	/**
	 * 删除操作
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function doDelAct(){
		$id_list = array_values(I('id'));
		if($id_list){
			$mod = new CommonModel('ProductSpreadad');
			$data['id'] = array('in',$id_list);
			$mod->where($data)->delete();
		}
		$this->success('删除成功', U('index'));
	}	
	
	/**
	 * 删除缓商品列表页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function doDelCacheAct(){
		F_CACHE($this->savePath.'pc',null);
		F_CACHE($this->savePath.'mobile',null);
		$this->success('商品数据已从缓存中删除');
	}

}

?>